home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / UTILITY1 / MSWSRC35.ZIP / LOGODATA.CPP < prev    next >
C/C++ Source or Header  |  1993-08-19  |  13KB  |  637 lines

  1. /*
  2.  *      logodata.c      logo data management module             dvb
  3.  *
  4.  *    Copyright (C) 1989 The Regents of the University of California
  5.  *    This Software may be copied and distributed for educational,
  6.  *    research, and not for profit purposes provided that this
  7.  *    copyright and statement are included in all such copies.
  8.  *
  9.  */
  10.  
  11. #include "logo.h"
  12. #include "globals.h"
  13. #include <stdlib.h>
  14. #include <stdarg.h>
  15. #include <string.h>
  16. #ifdef ibm
  17. #ifndef __ZTC__
  18. #include <alloc.h>
  19. #endif
  20. #endif
  21.  
  22. char special_chars[] = " \t\n()[]+-*/=<>\"\\~:;|?";
  23.  
  24. #ifdef ecma
  25.  
  26. #include <iso_ctype.h>
  27.  
  28. #define upper_p(ch)    (isupper((ch) & 0377))
  29. #define lower_p(ch)    (islower((ch) & 0377))
  30.  
  31. char ecma_array[128];
  32.  
  33. int ecma_size = sizeof(special_chars);
  34.  
  35. char ecma_set(int ch)
  36. {
  37.     ch &= 0377;
  38.     if (ch >= 0200) return(ch);
  39.     return(ecma_array[ch]);
  40. }
  41.  
  42. char ecma_clear(int ch)
  43. {
  44.     ch &= 0377;
  45.     if (ch < 0200 || ch >= 0200+sizeof(special_chars)) return(ch);
  46.     return(special_chars[ch - 0200]);
  47. }
  48.  
  49. int ecma_get(int ch)
  50. {
  51.     ch &= 0377;
  52.     return (ch >= 0200 && ch < 0200+sizeof(special_chars));
  53. }
  54.  
  55. #else
  56.  
  57. #define upper_p(c)     (c >= 'A' && c <= 'Z')
  58. #define lower_p(c)     (c >= 'a' && c <= 'z')
  59.  
  60. #endif
  61.  
  62. char *strnzcpy(char *s1, char *s2, int n)
  63. {
  64.     strncpy(s1, s2, n);
  65.     s1[n] = '\0';
  66.     return(s1);
  67. }
  68.  
  69. char *word_strnzcpy(char *s1, NODE *kludge, int n)  /* KLUDGE! */
  70. {
  71.     char *temp = s1;
  72.  
  73.     while (kludge != NIL) {
  74.     strncpy(s1, getstrptr(car(kludge)), getstrlen(car(kludge)));
  75.     s1 += getstrlen(car(kludge));
  76.     kludge = cdr(kludge);
  77.     }
  78.     temp[n] = '\0';
  79.     return(temp);
  80. }
  81.  
  82. char *noparity_strnzcpy(char *s1, char *s2, int n)
  83. {
  84.     int i;
  85.  
  86.     for (i = 0; i < n; i++)
  87.     s1[i] = clearparity(s2[i]);
  88.     s1[n] = '\0';
  89.     return(s1);
  90. }
  91.  
  92. char *mend_strnzcpy(char *s1, char *s2, int n)
  93. {
  94.     int i, vbar = 0;
  95.  
  96.     for (i = 0; i < n; ) {
  97.     while (*s2 == '|') {
  98.         vbar = !vbar;
  99.         s2++;
  100.     }
  101.     if (vbar) {
  102.         if (strchr(special_chars,(int)*s2))
  103.         s1[i++] = setparity(*s2++);
  104.         else
  105.         s1[i++] = *s2++;
  106.     } else {
  107.         while (*s2 == ';' || (*s2 == '~' && *(s2 + 1) == '\n')) {
  108.         while (*s2 == '~' && *(s2 + 1) == '\n') s2 += 2;
  109.         if (*s2 == ';')
  110.             do {
  111.             s2++;
  112.             } while (*s2 != '\0' && *s2 != '~' && *(s2 + 1) != '\n');
  113.         }
  114.         if (*s2 != '|') s1[i++] = *s2++;
  115.     }
  116.     }
  117.     s1[n] = '\0';
  118.     return(s1);
  119. }
  120.  
  121. char *mend_nosemi(char *s1, char *s2, int n)
  122. {
  123.     int i, vbar = 0;
  124.  
  125.     for (i = 0; i < n; ) {
  126.     while (*s2 == '|') {
  127.         vbar = !vbar;
  128.         s2++;
  129.     }
  130.     if (vbar) {
  131.         if (strchr(special_chars,(int)*s2))
  132.         s1[i++] = setparity(*s2++);
  133.         else
  134.         s1[i++] = *s2++;
  135.     } else {
  136.         while ((*s2 == '~' && *(s2 + 1) == '\n')) {
  137.         while (*s2 == '~' && *(s2 + 1) == '\n') s2 += 2;
  138.         }
  139.         if (*s2 != '|') s1[i++] = *s2++;
  140.     }
  141.     }
  142.     s1[n] = '\0';
  143.     return(s1);
  144. }
  145.  
  146. char *quote_strnzcpy(char *s1, char *s2, int n)
  147. {
  148.     s1[0] = '"';
  149.     strncpy(s1 + 1, s2, n - 1);
  150.     s1[n] = '\0';
  151.     return(s1);
  152. }
  153.  
  154. char *colon_strnzcpy(char *s1, char *s2, int n)
  155. {
  156.     s1[0] = ':';
  157.     strncpy(s1 + 1, s2, n - 1);
  158.     s1[n] = '\0';
  159.     return(s1);
  160. }
  161.  
  162. #define uncapital(c)    (c - 'A' + 'a')
  163.  
  164. char *low_strnzcpy(char *s1, char *s2, int n)
  165. {
  166.     char *temp = s1;
  167.     int i;
  168.  
  169.     for (i = 0; i < n; i++) {
  170.     if (upper_p(*s2))
  171.         *s1++ = uncapital(*s2++);
  172.     else
  173.         *s1++ = *s2++;
  174.     }
  175.     *s1 = '\0';
  176.     return(temp);
  177. }
  178.  
  179. #define capital(c)    (c - 'a' + 'A')
  180.  
  181. char *cap_strnzcpy(char *s1, char *s2, int n)
  182. {
  183.     char *temp = s1;
  184.     int i;
  185.  
  186.     for (i = 0; i < n; i++) {
  187.     if (lower_p(*s2))
  188.         *s1++ = capital(*s2++);
  189.     else
  190.         *s1++ = *s2++;
  191.     }
  192.     *s1 = '\0';
  193.     return(temp);
  194. }
  195.  
  196. char *noparitylow_strnzcpy(char *s1, char *s2, int n)
  197. {
  198.     int i;
  199.     char c, *temp = s1;
  200.  
  201.     for (i = 0; i < n; i++) {
  202.     c = clearparity(*s2++);
  203.     if (upper_p(c))
  204.         *s1++ = uncapital(c);
  205.     else
  206.         *s1++ = c;
  207.     }
  208.     *s1 = '\0';
  209.     return(temp);
  210. }
  211.  
  212. int low_strncmp(char *s1, char *s2, int n)
  213. {
  214.     int i;
  215.  
  216.     for (i = 0; i < n; i++) {
  217.     if (*s1 != *s2) {
  218.         if (upper_p(*s2)) {
  219.         if (upper_p(*s1)) {
  220.             if (uncapital(*s1) != uncapital(*s2))
  221.             return(uncapital(*s1) - uncapital(*s2));
  222.         } else {
  223.             if (*s1 != uncapital(*s2))
  224.             return(*s1 - uncapital(*s2));
  225.         }
  226.         } else if (upper_p(*s1)) {
  227.         if (uncapital(*s1) != *s2)
  228.             return(uncapital(*s1) - *s2);
  229.         } else return(*s1 - *s2);
  230.     }
  231.     s1++, s2++;
  232.     }
  233.     return(0);
  234. }
  235.  
  236. int noparity_strncmp(char *s1, char *s2, int n)
  237. {
  238.     int i;
  239.  
  240.     for (i = 0; i < n; i++) {
  241.     if (clearparity(*s1) != clearparity(*s2))
  242.         return(clearparity(*s1) - clearparity(*s2));
  243.     s1++, s2++;
  244.     }
  245.     return(0);
  246. }
  247.  
  248. int noparitylow_strncmp(char *s1, char *s2, int n)
  249. {
  250.     int i;
  251.     char c1, c2;
  252.  
  253.     for (i = 0; i < n; i++) {
  254.     c1 = clearparity(*s1);
  255.     c2 = clearparity(*s2);
  256.     if (c1 != c2) {
  257.         if (upper_p(c2)) {
  258.         if (upper_p(c1)) {
  259.             if (uncapital(c1) != uncapital(c2))
  260.             return(uncapital(c1) - uncapital(c2));
  261.         } else {
  262.             if (c1 != uncapital(c2))
  263.             return(c1 - uncapital(c2));
  264.         }
  265.         } else if (upper_p(c1)) {
  266.         if (uncapital(c1) != c2)
  267.             return(uncapital(c1) - c2);
  268.         } else return(c1 - c2);
  269.     }
  270.     s1++, s2++;
  271.     }
  272.     return(0);
  273. }
  274.  
  275. NODE *make_strnode(char *strptr, char *strhead, int len,
  276.            NODETYPES typ, char *(*copy_routine)(char *, char *, int))
  277. {
  278.     NODE *strnode;
  279.  
  280.     if (len == 0 && Null_Word != NIL) return(Null_Word);
  281.     strnode = newnode(typ);
  282.     if (strhead == NULL) {
  283.     strhead = (char *) malloc((size_t)len + 2);
  284.     (*copy_routine) (strhead + 1, strptr, len);
  285.     strptr = strhead + 1;
  286.     setstrrefcnt(strhead, 0);
  287.     }
  288.     setstrlen(strnode, len);
  289.     setstrptr(strnode, strptr);
  290.     setstrhead(strnode, strhead);
  291.     incstrrefcnt(strhead);
  292.     return(strnode);
  293. }
  294.  
  295. void make_runparse(NODE *ndi)
  296. {
  297.     NODE *rp_list;
  298.  
  299.     rp_list = runparse(ndi);
  300.     ref(rp_list);    /* I don't understand why this is necessary. */
  301.     setobject(ndi, rp_list);
  302.     settype(ndi, RUN_PARSE);
  303. }
  304.  
  305. NODE *make_quote(NODE *qnd)
  306. {
  307.     NODE *nd;
  308.  
  309.     nd = cons(qnd, NIL);
  310.     settype(nd, QUOTE);
  311.     return(nd);
  312. }
  313.  
  314. NODE *maybe_quote(NODE *nd)
  315. {
  316.     if (nd == UNBOUND || aggregate(nd) || numberp(nd)) return(nd);
  317.     return(make_quote(nd));
  318. }
  319.  
  320. NODE *make_caseobj(NODE *cstrnd, NODE *obj)
  321. {
  322.     NODE *nd;
  323.  
  324.     nd = cons(cstrnd, obj);
  325.     settype(nd, CASEOBJ);
  326.     return(nd);
  327. }
  328.  
  329. NODE *make_colon(NODE *cnd)
  330. {
  331.     NODE *nd;
  332.  
  333.     nd = cons(cnd, NIL);
  334.     settype(nd, COLON);
  335.     return(nd);
  336. }
  337.  
  338. NODE *make_intnode(FIXNUM i)
  339. {
  340.     NODE *nd = newnode(INT);
  341.  
  342.     setint(nd, i);
  343.     return(nd);
  344. }
  345.  
  346. NODE *make_floatnode(FLONUM f)
  347. {
  348.     NODE *nd = newnode(FLOAT);
  349.  
  350.     setfloat(nd, f);
  351.     return(nd);
  352. }
  353.  
  354. NODE *cnv_node_to_numnode(NODE *ndi)
  355. {
  356.     NODE *val;
  357.     int dr;
  358.     char s2[MAX_NUMBER], *s = s2;
  359.  
  360.     if (is_number(ndi))
  361.     return(ndi);
  362.     ndi = cnv_node_to_strnode(ndi);
  363.     if (ndi == UNBOUND) return(UNBOUND);
  364.     if (((getstrlen(ndi)) < MAX_NUMBER) && (dr = numberp(ndi))) {
  365.     if (backslashed(ndi))
  366.         noparity_strnzcpy(s, getstrptr(ndi), getstrlen(ndi));
  367.     else
  368.         strnzcpy(s, getstrptr(ndi), getstrlen(ndi));
  369.     if (*s == '+') ++s;
  370.     if (s2[getstrlen(ndi)-1] == '.') s2[getstrlen(ndi)-1] = 0;
  371.     if (dr - 1 || getstrlen(ndi) > 9) {
  372.         val = newnode(FLOAT);
  373.         setfloat(val, atof(s));
  374.     } else {
  375.         val = newnode(INT);
  376.         setint(val, atol(s));
  377.     }
  378.     gcref(ndi);
  379.     return(val);
  380.     } else {
  381.     gcref(ndi);
  382.     return(UNBOUND);
  383.     }
  384. }
  385.  
  386. NODE *cnv_node_to_strnode(NODE *nd)
  387. {
  388.     char s[MAX_NUMBER];
  389.  
  390.     if (nd == UNBOUND || aggregate(nd)) {
  391.     return(UNBOUND);
  392.     }
  393.     switch(nodetype(nd)) {
  394.     case STRING:
  395.     case BACKSLASH_STRING:
  396.     case VBAR_STRING:
  397.         return(nd);
  398.     case CASEOBJ:
  399.         return strnode__caseobj(nd);
  400.     case QUOTE:
  401.         nd = valref(cnv_node_to_strnode(node__quote(nd)));
  402.         nd = reref(nd, make_strnode(getstrptr(nd),
  403.                     (char *)NULL, getstrlen(nd) + 1,
  404.                     nodetype(nd), quote_strnzcpy));
  405.         unref(nd);
  406.